<?php
// +----------------------------------------------------------------------
// | Description: 用户组
// +----------------------------------------------------------------------
// | Author: linchuangbin <linchuangbin@honraytech.com>
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\logic\GroupLogic;
use app\common\validate\GroupValidate;
use app\common\controller\AdminAuthController;
use think\response\Json;

/**
 * Class Group
 * @package app\admin\controller
 */
class Group extends AdminAuthController
{
    /**
     * @var GroupValidate
     */
    public $validate;
    /**
     * @var GroupLogic
     */
    public $logic;

    /**
     * 初始化
     * @return bool|void
     */
    public function initialize()
    {
        parent::initialize();
        $this->logic = GroupLogic::instance();
        $this->validate = GroupValidate::instance();
        return TRUE;
    }

    /**
     * 数据列表
     * @return Json
     */
    /**
     * 数据列表
     * @return Json
     */
    public function index()
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $list = $this->logic->getList($param);
        $count = $this->logic->getCount($param);
        return $this->json_responce(compact(['list', 'count']));
    }

    /**
     * 数据详情
     * @return Json
     */
    public function read(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->getByID($param);
        return $this->json_responce($data);
    }

    /**
     * 新增数据
     * @return Json
     */
    public function save(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->createData($param);
        return $this->json_responce();
    }

    /**
     * 更新数据
     * @return Json
     */
    public function update()
    {
        $param = $this->param;
        GroupValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = GroupLogic::instance()->updateByID($param);
        return $this->json_responce();
    }

    /**
     * 删除单条数据
     * @return Json
     */
    public function delete(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->delByID($param);
        return $this->json_responce();
    }

    /**
     * 批量删除数据
     * @return Json
     */
    public function deletes(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->delByIDs($param);
        return $this->json_responce();
    }

    /**
     * 启用/禁用数据
     * @return Json
     */
    public function enables(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->enableByIDs($param);
        return $this->json_responce();
    }
}
